#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char flag[65540];
int start, end, head, tail, i, j, k, tox, toy, bitv, tobitv;
int movex[]={1,0};
int movey[]={0,1};
int p2[17];

typedef struct Node {
    int value;
    int father;
    int step;
    char x, y, order;
};
Node q[65540];
Node tmp;

inline void getbitv(int &v, int fx, int fy, int tx, int ty) 
{
     int k1, k2;
     k1 = fx*4 + fy;
     k2 = tx*4 + ty;
     int t1 = v & p2[k1];
     int t2 = v & p2[k2];
     if (t1) v = v | p2[k2];
     else    v = v & ~p2[k2];
     if (t2) v = v | p2[k1];
     else    v = v & ~p2[k1];
}   
 
void output(int head)
{
    int k;
    if (q[head].father != -1) 
    {
        output(q[head].father);
        k = q[head].order;
        printf("%d%d%d%d\n", q[head].x, q[head].y, q[head].x + movex[k], q[head].y + movey[k]);
    }    
}     
 
void wfs() {
    memset(flag, 0, sizeof(flag));
    head = 0;
    tail = 1;
    q[0].value = start;
    q[0].father = -1;
    q[0].step = 0;
    flag[start] = 1;
    while (head < tail) {
        tmp = q[head];
        //printf("fetch %d\n", tmp.value);
        if (tmp.value == end) 
            break;
        for (i=0; i<4; ++i)
            for (j=0; j<4; ++j) {
                for (k=0; k<2; ++k) {
                    tox = i + movex[k];
                    toy = j + movey[k];
                    if (tox<4 && toy<4) {
                        bitv = q[head].value;
                        getbitv(bitv, i, j, tox, toy);
                        if (flag[bitv]==0) {
                            flag[bitv] = 1;
                            q[tail].value = bitv;
                            q[tail].father = head;
                            q[tail].step = tmp.step + 1;
                            q[tail].x = i+1;
                            q[tail].y = j+1;
                            q[tail].order = k;
                            tail++;
                            // printf("expand %d\n", q[tail-1].value);
                        }    
                    }    
                }    
            }    
        head++;
    } // end of while 
    
    // output answer
    printf("%d\n", q[head].step);
    output(head);
}    


void init() {
    int i, j, v;
    char ss[5][5];
    // get start
    start = end = v = 0;
    for (i=0; i<4; ++i) {
        scanf("%s", ss[i]);
    } 
    v = 0;
    for (i=3; i>=0; --i)
        for (j=3; j>=0; --j)
            v = (v<<1) + ss[i][j]-'0';
    start = v;   
    // get end
    for (i=0; i<4; ++i) {
        scanf("%s", ss[i]);
    } 
    v = 0;
    for (i=3; i>=0; --i)
        for (j=3; j>=0; --j)
            v = (v<<1) + ss[i][j]-'0';
    end = v;
    p2[0] = 1;
    for (i=1; i<17; ++i)
        p2[i] = p2[i-1] << 1;
    //printf("%d %d\n", start, end);
}    

int main()
{
   // while (1) {
        init();
        wfs();   
   // }      
    // system("pause"); 
    return 0;
}    
/*
0001
1111
1111
1111
1000
1111
1111
1111
*/

